#include "InputManager.h"

InputManager::InputManager()
{
}

InputManager::~InputManager()
{
}

bool InputManager::handleKeys()
{
	//Get input
	auto key = TCODConsole::checkForKeypress();
	if(key.vk == TCODK_NONE)
		return true;

	bool handled = false;
	for(unsigned int i = 0; i < key_callbacks.size(); i++)
	{
		if(key_callbacks[i]->vk == key.vk && key_callbacks[i]->pressed == key.pressed)
		{
			key_callbacks[i]->callback(key);
			handled = true;
		}
	}
	return handled;
}

void InputManager::setKeyCallback(TCOD_keycode_t vk, uint8 pressed, std::function<void(TCOD_key_t)> callback)
{
	auto cb = std::make_shared<KeyCallback>();
	cb->vk = vk;
	cb->pressed = pressed;
	cb->callback = callback;
	key_callbacks.push_back(cb);
}
